<?php
namespace app\admin\controller;

use app\common\model\Goods as GoodsModel;
use app\common\model\User as UserModel;
use app\common\model\Order as OrderModel;
use app\common\model\Floor as FloorModel;
use app\common\model\Unit as UnitModel;
use app\common\model\Spec as SpecModel;
use app\common\controller\AdminBase;
use app\common\model\User;
use think\Cache;
use think\Db;

/**
 * 订单管理
 * Class Article
 * @package app\admin\controller
 */
class Order extends AdminBase
{
    protected $goods_model;
    protected $user_model;
    protected $order_model;
    protected $floor_model;
    protected $unit_model;
    protected $spec_model;
    protected function _initialize()
    {
        parent::_initialize();
        $this->goods_model  = new GoodsModel();
        $this->user_model = new UserModel();
        $this->order_model = new OrderModel();
        $this->floor_model = new FloorModel();
        $this->unit_model = new UnitModel();
        $this->spec_model = new SpecModel();
    }

    /**
     * 订单管理
     * @param int    $cid     分类ID
     * @param int    $is_condition     是否加精/置顶
     * @param string $keyword 关键词
     * @param int    $page
     * @return mixed
     */

    public function index($o_order_num ='',$u_email ='', $page = 1)
    {
        $map = [];
        if ($o_order_num){
            $orderNum = trim($o_order_num);
            $map = ['o_order_num'=>$orderNum];
        }
        if ($u_email) {
            $u_email = trim($u_email);
            $map['u_email'] = ['like', "%{$u_email}%"];
        }
        $list = \app\common\model\Order::index($map, $page);
        return $this->fetch('index', ['list' => $list, 'o_order_num' => $o_order_num, 'u_email' => $u_email]);
    }
    /**
     * 订单详情
     */
    public function detail($id)
    {
        $order = \app\common\model\Order::detail($id);
        return $this->fetch('detail', ['order' => $order]);
    }
    /**
     * 修改订单
     */
    public function update()
    {
        $params = input();
        $oid = \app\common\model\Order::updateStatus($params);
        if ($oid) {
            $this->success('更新成功');
        } else {
            $this->error('更新失败');
        }
    }


}